﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using BestCode.Creds.View.Model;
using BestCode.Creds.View.ViewModel;

namespace BestCode.Creds.View
{
    /// <summary>
    /// Interaction logic for VwEditFoto.xaml
    /// </summary>
    public partial class VwEditFoto : Window
    {
        private VmEditFoto viewmodel = null;

        public VwEditFoto(Dato entity)
        {
           
            viewmodel = new VmEditFoto();
            viewmodel.SelectedStudent = entity;
            this.DataContext = viewmodel;
            InitializeComponent();
            Loaded += VwEditFoto_Loaded;

        }

        void VwEditFoto_Loaded(object sender, RoutedEventArgs e)
        {
            txtFoto.SelectAll();
            txtFoto.Focus();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            HandleUpdate();
        }

        public void HandleUpdate()
        {
            viewmodel.UpdateFoto();
            this.Close();
        }

        private void TxtFoto_OnKeyUp(object sender, KeyEventArgs e)
        {
            if(e.Key== Key.Enter)
                HandleUpdate();
        }

    }
}
